package com.gk.javaservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.gk.javaservice.util.javaRequest.HttpUtilNew;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/http")
public class HttpConteoller {

    private Logger log = Logger.getLogger(this.getClass());


    @CrossOrigin
    @ResponseBody
    @RequestMapping("/sendPostCHN")
    public JSONObject sendPostCHN(@RequestBody JSONObject para) {
        log.info("in ot sendPostCHN");
        String url = para.getString("url");
        JSONObject value = para.getJSONObject("value");
        log.info(url);
        log.info(value);
        JSONObject msg = HttpUtilNew.sendPostCHN(url, value.toString());
//        JSONObject msg = HttpUtil.doPost("http://"+ip+"/web/activeProtocol.action", value);

        return msg;

    }

    @CrossOrigin
    @ResponseBody
    @RequestMapping("/doGet")
    public JSONObject doGet(@RequestBody JSONObject para) {
        log.info("in ot doGet");

        String url = para.getString("url");
        JSONObject value = para.getJSONObject("value");
        log.info(url);
        log.info(value);
        JSONObject msg = HttpUtilNew.doGet(url, value);
        return msg;

    }


}
